package com.wangpu.oa.web.servlet.rolemanege;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.wangpu.oa.dto.UserContext;
import com.wangpu.oa.entity.RoleEntity;
import com.wangpu.oa.exception.OAException;
import com.wangpu.oa.service.RoleService;
import com.wangpu.oa.service.impl.RoleServiceImpl;
@WebServlet("/system/role/list.do")
public class ListServlet extends HttpServlet{

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		try {
			
			RoleService service=new RoleServiceImpl();
			HttpSession session=req.getSession();
			UserContext uc=(UserContext) session.getAttribute("CURRENT-USER");
			List<RoleEntity> queryResult=service.queryRole(uc.getId());
			
			// 3 进行视图处理
			req.setAttribute("rows", queryResult);
			req.getRequestDispatcher("/rolemanage/list.jsp").forward(req, resp);
			
		} catch (OAException e) {
			req.setAttribute("message", e.getMessage());
		} catch (Exception e) {
			resp.sendError(500);
			//打印异常信息，用于调试
			e.printStackTrace();
		}
		
	}
}
